package com.example.myinitializrspringbootapp.config;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration  //配置类注解
public class TomcatWebServerFactoryConfig {
    /**
     * 方法一:
     * 配置当前web容器Tomcat
     */

    /*@Bean   //设置一个bean
    public TomcatServletWebServerFactory webServerFactory(){
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.setPort(8083);  //设置端口号
        factory.setContextPath("/index");  //设置上下文路径
        return factory;
    }*/

    /**
     * 方法二:
     * 配置WebServerFactoryCustomizer,重写customize()方法,强转相应的TomcatServletWebServerFactory
     */
   /* @Bean         //WebServerFactoryCustomizer 是Spring框架中的一个接口，用于自定义和配置Spring Boot应用程序中的嵌入式Web服务器
    public WebServerFactoryCustomizer customizer(){
        WebServerFactoryCustomizer customizer=new WebServerFactoryCustomizer() {
            @Override
            public void customize(WebServerFactory factory) {
                TomcatServletWebServerFactory factory1= (TomcatServletWebServerFactory) factory;
                factory1.setPort(8082);
            }
        };
        return customizer;
    }*/
}
